package game;

import jw.gui.Point;
import jw.gui.Win;
import jw.gui.anima.GifAnima;
import jw.gui.anima.MoveAnima;
import jw.gui.view.ImageView;

/**
 * 小鸟宠物
 */
public class Bird extends Pet{

    /**
     * 宠物鸟显示的动画图片 ， 因为不会变动，所以用常态数组存储
     */
    final String[] birdGif= 
    {
        "image/bird_1.png",
        "image/bird_2.png",
        "image/bird_3.png",
        "image/bird_4.png",
        "image/bird_5.png",
        "image/bird_6.png",
        "image/bird_7.png",
        "image/bird_8.png",
    };

    /**
     * 宠物鸟 移动的坐标集合，因为不会变动，所以用常态方法
     * @return
     */
    final Point[] birdMove()
    {
        //把整个屏幕宽度计算成48份，动态运动步伐
        final int birdNum = 24;
        Point[] gifPoint = new Point[birdNum];
        int mid = (win.width()/birdNum);

        //宠物移动策略 从原点 y坐标不变 水平移动一圈
        for(int i=0;i<birdNum/2;i++)
        {
            gifPoint[i] = new Point(i*mid, 0);
            gifPoint[birdNum/2+i] = new Point(i*mid-petX, 0);
        }
        return gifPoint;
    }

    //宠物的大小 用常态 便于修改
    final int petWidth = 200,petHeight = 200;
    //宠物显示的坐标
    private int petX,petY;
    
    /**
     *  构造方法 根据鸟的特性 重写构造方法
     * @param win 窗口对象
     * @param name 宠物名字
     */
    public Bird(Win win,String name) {
        super(win,name);
        //TODO Auto-generated constructor stub

        //计算宠物位于屏幕终点的坐标
        petX = (win.width()-petWidth)/2;
        petY = (win.height()-petHeight)/2;

        imageView.image().name(birdGif[0]);

        imageView.x(petX);
        imageView.y(petY);
        imageView.size(petWidth, petHeight);

        /**
         * 添加动画
         */
        gifAnima = new GifAnima(imageView, birdGif, 1, -1);
        moveAnima = new MoveAnima(imageView, birdMove(), 1, 1);

        //启动宠物动画 
        gifAnima.start();
    }
    
    
    ImageView imageView = new ImageView();
    GifAnima gifAnima;
    MoveAnima moveAnima;
    

    @Override
    public void eat() {
        // TODO Auto-generated method stub
        super.eat();
    }

    @Override
    public boolean run() {
        // TODO Auto-generated method stub
        if(super.run())
        {
            //饥饿值满足条件 开始运动
            moveAnima.start();
        }
        return true;
    }
    @Override
    public void show() {
        // TODO Auto-generated method stub
        super.show();
        win.add(imageView);
    }
    @Override
    public void hide() {
        // TODO Auto-generated method stub
        super.hide();
        win.remove(imageView);
    }

    
}
